<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script>
        //1
        console.log(a);//undefined
        var a = 10;
        console.log(a);//10

        //2
        foo();
        function foo() {
            console.log('Hello');           
        }
        
        //3
        function func() {
            var b = 20;
            fn1();
            function fn1() {
                console.log(b);
                //b这个变量在当前作用域查找如果没有 会一直向一层作用域查找
                //直到找到为止 或者 找不到就报错 'b is not defined'
            }
        }
        func();

        //4
        function fn2() {
            var count = 100;
        }
        // console.log(count);报错
        fn2();
        // console.log(count);报错

        //5
        function fn3(num) {
            console.log(num);//200
            var num = 150; //重复声明变量 不过赋值 变量的值会改变
            console.log(num);//150            
        }
        fn3(200);

        //6
        function fn4(k) {
            console.log(k);//250
            var k;//重复声明变量 如果没有赋值 值不会改变
            console.log(k);//undefined            
        }
        fn4(250)

        //7
        function fn5(fo1) {
            console.log(fo1);//函数
            function fo1() {
                console.log('函数fo1');                
            }
            console.log(fo1);//函数
        }
        fn5(300);
        //命名函数 预解析会提升 将整个函数体 都提前 解析
    </script>
</body>
</html>